home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / _archvrs / unix / comp430 / compress.h < prev    next >
C/C++ Source or Header  |  1990-01-17  |  28KB  |  795 lines

  1. /*@H************************ < COMPRESS HEADER > ***************************/
  2. #define TITLE "$@(#) compress.h,v 4.3d 90/01/18 03:00:00 don Release ^"
  3. /*                                                                          *
  4. *   compress : compress.h <global defines, etc>                             *
  5. *                                                                           *
  6. *   port by  : Donald J. Gloistein                                          *
  7. *                                                                           *
  8. *   Source, Documentation, Object Code:                                     *
  9. *   released to Public Domain.  This code is based on code as documented    *
  10. *   below in release notes.                                                 *
  11. *                                                                           *
  12. *---------------------------  Module Description  --------------------------*
  13. *   THIS HEADER CONTAINS MUCH IMPLEMENTATION INFORMATION AND ASSUMPTIONS    *
  14. *   PLEASE PRINT IT OUT AND READ IT BEFORE COMPILING CODE FOR YOURSELF      *
  15. *                                                                           *
  16. *   This header supports a number of compiler defines and predefines.       *
  17. *   Rather than explain all of them, please print the header and read the   *
  18. *   notes. Also the unix and xenix makefiles are commented for the          *
  19. *   various options. There continues to have a lot of Dos specific info in  *
  20. *   the header. This is to help on 16 bit Msdos machines to get their       *
  21. *   compiler to work properly. I make no appology for that, as this port    *
  22. *   began as a way to implement 16 bit compress on a segmented MsDos machine*
  23. *                                                                           *
  24. *   However, for Unix and Xenix, all you should have to define is -DXENIX   *
  25. *   or -DUNIX and compile. There may be a problem with whether your library *
  26. *   supports alloc() or malloc(), but there is a define for that, also.     *
  27. *                                                                           *
  28. *   This header can be maintained to keep up with the different compilers   *
  29. *   and systems. As distributed in don Release, the files will compile with *
  30. *   no changes under Microsoft version 5.1 C compiler, and Xenix C compiler *
  31. *   which is the Microsoft version 4 ported. If you are going to bind the   *
  32. *   code for use in MsDos and OS/2 machines, then you must uncomment the    *
  33. *   #define BIND in this header. Otherwise, this distribution of source     *
  34. *   detect Msdos and Xenix predefines from the compiler and adjust.         *
  35. *                                                                           *
  36. *--------------------------- Implementation Notes --------------------------*
  37. *                                                                           *
  38. *   compiled with : compress.fns                                            *
  39. *
  40. *   NOTE!!!  Defaults of this code now are completely Unix, even for the    *
  41. *            msdos ports.  That means that the program works as a filter,   *
  42. *            and will just sit there waiting for input from stdin if you    *
  43. *            issue just the command name. You must use -h or -? to get the  *
  44. *            full help screen now. Also, it will unlink (kill) as a default *
  45. *            on successful compression and decompression. That means the    *
  46. *            source file will be erased.                                    *
  47. *            These defaults are changed with the FILTER and KEEPFLAG        *
  48. *            defines.                                                       *
  49. *                                                                           *
  50. *   NOTE!!!  Compiler predefines were taken out of the compress.h header.   *
  51. *            You must either specify them on compile or uncomment the       *
  52. *            compiler define in this header. Compiling without doing these  *
  53. *            will result in a program that does unspecified actions.        *
  54. *   problems:                                                               *
  55. *            The inpath and outpath is a bit kludged. It should work okay.  *
  56. *            Let me know if you have problems, especially under Unix.       *
  57. *                                                                           *
  58. *   CAUTION: The bound version will run on Dos 2.x, but you must use the    *
  59. *            name compress.exe.  If you rename the file, it will not run    *
  60. *            The unbound version will run on Dos 2.x with the name changed  *
  61. *            but due to the dos version, will not detect its own name.      *
  62. *                                                                           *
  63. *   CAUTION: Non MsDos users. You must modify the _MAX_PATH defines for     *
  64. *            your operating system if it is different from the assumed      *
  65. *            standard.                                                      *
  66. *                                                                           *
  67. *   CAUTION: I have used a number of defines to make it possible to compile *
  68. *            properly under a number of bit sizes and adjust for the memory *
  69. *            allocation scheme needed. If you do not use a dos system,      *
  70. *            PLEASE pay attention to the defines for MAXSEG_64K and the one *
  71. *            called SMALLMODEL. The SMALLMODEL define is set in the header  *
  72. *            but if you don't have a compiler that triggers the MAXSEG_64K  *
  73. *            define, you may end up with bad pointers. Becareful.           *
  74. *                                                                           *
  75. *   Header for files using version 4 compress routines define MAIN          *
  76. *   in the file with defining instance of the global variables.             *
  77. *   There are a number of compilers for MsDos and Unix/Xenix.               *
  78. *   So the user must define the actions required.                           *
  79. *                                                                           *
  80. *                                                                           *
  81. *   Defines:  This header file contains most of the system wide defines.    *
  82. *             the purpose for this was to consolodate compiler differences  *
  83. *             into one area that is easily changed.                         *
  84. *                                                                           *
  85. *   define MAXBITS= if you want a different maximum bits. 16 bits will now  *
  86. *   run in about 400K of memory.                                            *
  87. *   define BIND if you are going to use Microsoft bind.exe program on the   *
  88. *   executable.                                                             *
  89. *                                                                           *
  90. *   define MSDOS if you are compiling under MsDos or PcDos and your compiler*
  91. *   does not predefine it.                                                  *
  92. *                                                                           *
  93. *     Initials ---- Name ---------------------------------                  *
  94. *      DjG          Donald J. Gloistein, current port to MsDos 16 bit       *
  95. *                   Plus many others, see rev.hst file for full list        *
  96. *      Dal          Dale A. Schumacher (Sozobon C port)                     *
  97. *      LvR          Lyle V. Rains, many thanks for improved implementation  *
  98. *                   of the compression and decompression routines.          *
  99. *************************************************************************@H*/
  100.  
  101. #ifndef FALSE            /* let's get some sense to this */
  102. #define FALSE 0
  103. #define TRUE !FALSE
  104. #endif
  105.  
  106. #ifndef DEBUG           /* some convoluted defines to make the source */
  107. #ifndef NDEBUG          /* on command line use -DNDEBUG to make a     */
  108. #define DEBUG         /* program without the debugging routines     */
  109. #endif
  110. #endif
  111.  
  112. #ifdef TOLZ
  113. #define FILTER FALSE
  114. #define KEEPFLAG TRUE
  115. #endif
  116.  
  117. #ifdef UNIX
  118. #define NPROTO
  119. #define COMP40           /* take this out for a little more speed */
  120. #ifdef ALLOC
  121. char *alloc();
  122. #define ALLOCATE(x,y)   alloc((unsigned int)x*y)
  123. #else
  124. char *malloc();
  125. #define ALLOCATE(x,y)   malloc((unsigned int)x*y)
  126. #endif
  127. #define FREEIT(ptr)     free(ptr)
  128. #define setbinary(fp)
  129. #define NO_SETVBUF      /* most don't support setvbuf() function */
  130. #endif
  131.  
  132. #ifdef ISC386           /* my unix version compiler and system DjG */
  133. #define NPROTO          /* the unix release 3.2 dose not support prototypes */
  134. /* #define COMP40 */    /* took this out for a little more speed */
  135. #include <malloc.h>     /* compiler has it, so put it in for future */
  136. #define ALLOCATE(x,y)   malloc((unsigned int)x*y)
  137. #define FREEIT(ptr)     free(ptr)
  138. #define setbinary(fp)
  139. #include <limits.h>
  140. #define _MAX_PATH  PATH_MAX
  141. #define _MAX_NAME  NAME_MAX
  142. #define _MAX_DIR   (PATH_MAX + NAME_MAX)
  143. #define UNIX      /* the rest of the unix stuff is still good */
  144. #define COMPVER "386/ix"
  145. #endif
  146.  
  147.                           /* Microsoft C compiler  v 4.0-5.1 */
  148.                           /* MSC is defined in makefile.msc        */
  149. #ifdef MSC
  150. #define COMPVER "Msdos"
  151. #define FAR far        
  152. #define MAXSEG_64K
  153. #define NO_REVSEARCH
  154. #define CONST const
  155. #define ALLOCTYPE void
  156. #ifdef M_I86SM
  157. #define SMALLMODEL        /* compiled in small model */
  158. #endif
  159. #define setbinary(fp)    setmode(fileno((fp)), O_BINARY)
  160. #endif
  161.  
  162. /*  MINIX adaptions
  163. NOTE: This program will not work on the IBM/PC version of MINIX due to
  164. the small memory model restrictions.  There is no such thing as a FAR
  165. pointer in MINIX-PC
  166. */
  167.  
  168. #ifdef MINIX        /* Unix V7 clone for Atari ST */
  169. #define COMPVER "minix"
  170. #define strchr  index
  171. #define strrchr rindex
  172. #define DFLTBITS 13 /* compatible with original MINIX compress, max=16 */
  173. #ifndef KEEPFLAG
  174. #define KEEPFLAG 1  /* compatible with original MINIX compress */
  175. #endif             /* may be redefined from the Makefile if desired */
  176. #ifndef VERBOSE
  177. #define VERBOSE TRUE    /* compatible with original MINIX compress */
  178. #endif            /* may be redefined from the Makefile if desired */
  179. #define NPROTO
  180. #define SIGTYPE int /* MINIX defines this as pointer to int */
  181.                     /* for the return from a signal         */
  182. #endif      /* end of MINIX changes */
  183.  
  184.  
  185. /* Mark Williams C for ATARI ST (V3.0.5) MWC is defined in makefile.mwc */
  186. #ifdef MWC
  187. #define COMPVER "TOS(mwc)"
  188. #define MSDOS
  189. #define NOSIGNAL
  190. #define DFLTBITS 14
  191. #define NPROTO
  192. /* #define MAXSEG_64K */  /* use this if your compiler has a problem with */
  193.                           /* indexing arrays larger than 64k              */
  194. #define NO_SETVBUF
  195. #define NO_REVSEARCH
  196. #define ALLOCATE(x,y)   lcalloc((unsigned long)(x),((unsigned long)(unsigned)(y)))
  197. #define FREEIT(ptr)     free(ptr)
  198. #define setbinary(fp)    ((fp)->_ff &= ~_FASCII)
  199. #endif
  200.  
  201. /*
  202. Sozobon or Alcyon (4.14) C for Atari ST used with the dLibs standard library
  203. */
  204. #ifdef ALCYON
  205. #define SOZOBON 1
  206. #endif
  207.  
  208. #ifdef SOZOBON
  209. #define COMPVER "TOS(sozobon)"
  210. #define MSDOS
  211. #define NOSIGNAL
  212. #define DFLTBITS 14
  213. #define NPROTO
  214. /* #define MAXSEG_64K */  /* use this if your compiler has a problem with */
  215.                           /* indexing arrays larger than 64k              */
  216. #define ALLOCATE(x,y)   lalloc((unsigned long)(x) * ((unsigned long)(y)))
  217. #define FREEIT(ptr)     free(ptr)
  218. #define setbinary(fp)    ((fp)->_flag |= _IOBIN)
  219. #define FILTER  FALSE
  220. #endif
  221.  
  222. #ifdef __ZTC__                 /* Zortech compiler           */
  223. #define setbinary(fp)    ((fp)->_flag&=~_IOTRAN)
  224. #define NO_REVSEARCH
  225. #define CONST const
  226. #define MAXSEG_64K
  227. #endif
  228.  
  229. #ifdef XENIX
  230. #define setbinary(fp)
  231. #define FAR far
  232. #define CONST
  233. #define SIGTYPE int           /* xenix defines this as pointer to int */
  234.                               /* for the return from a signal         */
  235. #ifdef M_I286
  236. #define MAXSEG_64K
  237. #endif
  238. #define NO_SETVBUF            /* evidently xenix chokes on the large buff*/
  239. #endif                        /* really needs to be fine tuned           */
  240.  
  241. #ifdef MCH_AMIGA
  242. #define COMPVER "Amiga"
  243. #define CONST
  244. #define MAXSEG_64K             /* Manx C compiler limitation */
  245. #define NO_SETVBUF
  246. #endif
  247.  
  248. #ifdef vms
  249. #define NO_SETVBUF
  250. #endif
  251.  
  252. #ifdef __TURBOC__
  253. #define MSDOS
  254. #define MAXSEG_64K
  255. #define NO_REVSEARCH
  256. #ifdef __SMALL__
  257. #define SMALLMODEL
  258. #endif
  259. #define CONST const
  260. #define FAR             far
  261. #define setbinary(fp)   setmode(fileno((fp)), O_BINARY)
  262. #endif
  263.  
  264. /* FILTER  if you want the program to operate as a unix type filter */
  265. /*  if not defined TRUE, then issuing command without parameters will */
  266. /*  print a usage and help information                              */
  267. /*  Use -DFILTER=0 to deactivate filter operation                   */
  268. #ifndef FILTER
  269. #define FILTER  TRUE
  270. #endif
  271.  
  272. /* KEEPFLAG determines the default action on successful completion */
  273. /* Unix convention is FALSE (erase input file)                     */
  274. /* Use -DKEEPFLAG=1 to keep files as default or change here        */
  275. /* if you don't set it before here and you are compiling the debug */
  276. /* version, then files will be kept.                               */
  277.  
  278. #ifndef KEEPFLAG
  279. #ifdef DEBUG
  280. #define KEEPFLAG TRUE
  281. #else
  282. #define KEEPFLAG FALSE
  283. #endif
  284. #endif
  285.  
  286.  
  287. /* Does your compiler support extended prototyping?  */
  288. /* Uncomment the following if your compiler does not.*/
  289. /* support full prototyping, such as:                */
  290. /*      char *emalloc(unsigned,int);                 */
  291. /* if defined it will use the following:             */
  292. /*      char *emalloc();                             */
  293. /* #define NPROTO */
  294.  
  295. /* putting the include files in one location */
  296.  
  297. #include <ctype.h>
  298.  
  299. #ifdef MINIX
  300. #define assert(x)
  301. extern char *index(), *rindex(), *strcat(), *strcpy(), *strncat(), *strncpy();
  302. #else
  303. #include <assert.h>
  304. #include <string.h>
  305. #endif
  306.  
  307. #ifndef NOSIGNAL
  308. #include <signal.h>
  309. #endif
  310.  
  311. #ifdef MWC
  312. #include <stdlib.h>
  313. #include <types.h>
  314. #include <stat.h>
  315. #else
  316. #ifdef SOZOBON
  317. #include <stdio.h>
  318. #include <stat.h>
  319. #include <limits.h>
  320. #include <malloc.h>
  321. #include <errno.h>
  322. #else
  323. #include <sys/types.h>
  324. #include <sys/stat.h>
  325. #endif
  326. #endif
  327.  
  328. #ifdef M_XENIX
  329. #include <fcntl.h>
  330. #endif
  331.  
  332.  
  333. #ifdef MSC
  334. #include <stdlib.h>
  335. #include <io.h>
  336. #include <sys/utime.h>
  337. #include <fcntl.h>
  338. #include <limits.h>
  339. #endif
  340.  
  341. #ifdef __TURBOC__
  342. #include <stdlib.h>
  343. #include <io.h>
  344. #include <fcntl.h>
  345. #include <limits.h>
  346. #endif
  347.  
  348. #ifndef NOSIGNAL
  349. #ifndef SIGTYPE
  350. #define SIGTYPE void
  351. #endif
  352. #ifndef SIG_ERR
  353. #define SIG_ERR (SIGTYPE(*)())-1
  354. #endif
  355. #endif
  356.  
  357. /* This is for Microsoft C v5.1 to compile and be bound  */
  358. /* for use with os/2.  Also if compiled just for os/2    */
  359. /* The signal function is different between protected    */
  360. /* and real mode.                                        */
  361.  
  362. /* #define BIND */
  363.  
  364. #ifdef INCL_DOSPROCESS
  365. #define ISOS2 TRUE
  366. #endif
  367.  
  368. #ifdef BIND
  369. #define ISOS2 TRUE
  370. #endif
  371.  
  372. /*  The following is defined in MSC 5.1 stdlib.h
  373.     Replace with appropriate values for your system.
  374.     These values are used for MSDos system.
  375. */
  376. #ifndef _MAX_PATH
  377. #define _MAX_PATH  144      /* max. length of full pathname       */
  378. #define _MAX_DRIVE   3      /* max. length of drive component     */
  379. #define _MAX_DIR   130      /* max. length of path component      */
  380. #define _MAX_FNAME   9      /* max. length of file name component */
  381. #define _MAX_EXT     5      /* max. length of extension component */
  382. #endif
  383.  
  384. /* the following tells the system that the maximum segment is 64k */
  385. /* if your compiler is not one of these and has this limitation   */
  386. /* Because of this, this code should compile with minimum porting */
  387. /* in the COMPUSI.UNI module to most unix systems.                */
  388. /* This is also used to keep array indexing to 16 bit integer     */
  389. /* if not predefined in compiler implementation, you must define  */
  390. /* it separately if applicable to your compiler/system            */
  391. /* #define MAXSEG_64K                                             */
  392.  
  393. /* put this in if you are compiling in small code */
  394. /* model and your compiler does not predefine it  */
  395. /* this is for CPU' with 64k segment limitation.  */
  396. /* Use this define for small code, it is used by  */
  397. /* the header to decide on value for NEARHEAP     */
  398. /* #define SMALLMODEL */
  399.  
  400. /* does your system use far pointers ? if you want it enabled keep this */
  401. /* if you have segment limit and compile in larger than 13 bits         */
  402. /* then you will have to use compact or large model if your compiler    */
  403. /* does not support far pointer keyword.                                */
  404.  
  405. #ifndef FAR
  406. #define FAR
  407. #endif
  408.  
  409. /* What type does the alloc() function return, char or void? */
  410.  
  411. #ifndef ALLOCTYPE
  412. #define ALLOCTYPE char
  413. #endif
  414.  
  415. /* If you use compusi.dos and your computer supports the unix */
  416. /* file links and the link code is set properly in the stat() */
  417. /* then define the following:                                 */
  418. /* #define USE_LINKS */
  419.  
  420. /* Does your run time library support the ANSI functions for:*/
  421.  
  422. /* reverse string set search?  strrpbrk() if so:             */
  423. /*#define NO_REVSEARCH*//* dos module uses this function. */
  424.  
  425. /* Does your library include strrchr()? If not define this:  */
  426. /*#define NO_STRRCHR*//* unix/xenix module uses this function*/
  427.  
  428. /* Does your library include strchr()? If not define this:   */
  429. /*#define NO_STRCHR*//* dos module uses this function.       */
  430.  
  431. /* definition for const key word if supported */
  432. #ifndef CONST
  433. #define CONST
  434. #endif
  435.  
  436.  
  437. /*  And now for some typedefs */
  438. typedef unsigned short CODE;
  439. typedef unsigned char UCHAR;
  440. typedef unsigned int  INTCODE;
  441. typedef unsigned int HASH;
  442. typedef int FLAG;
  443.  
  444.   /* 
  445.    * You can define the value of MAXBITS to be anything betweeen MINBITS
  446.    * and MAXMAXBITS.  This is will determine the maximum memory you will
  447.    * use and how the tables will be handled.  I recommend you just leave
  448.    * it at MAXMAXBITS, because you can define DFLTBITS in compiling the
  449.    * module COMPRESS.C to set the default, and you can vary the number
  450.    * of bits at runtime by using the -b switch.
  451.    */
  452.  
  453.    /*
  454.    * The only reason to change MAXBITS is if you absolutely must have
  455.    * faster performance. If you specify 14 bits, the tables will not
  456.    * be split; at 13 bits, you can fit in the MSDOS small memory model
  457.    * and allocate tables in near heap.
  458.    * This value is available to other modules through the variable maxbits.
  459.    */
  460.  
  461. #define INITBITS    9
  462. #define MINBITS     12
  463. #define MAXMAXBITS  16
  464.  
  465. #ifndef MAXBITS
  466. #define MAXBITS    MAXMAXBITS
  467. #endif
  468.  
  469. #if (MAXBITS > MAXMAXBITS)
  470. #undef MAXBITS
  471. #define MAXBITS    MAXMAXBITS
  472. #endif
  473.  
  474. #if (MAXBITS < MINBITS)
  475. #undef MAXBITS
  476. #define MAXBITS  MINBITS
  477. #endif
  478.  
  479.   /* You should define DFLTBITS to be the default compression code
  480.    * bit length you desire on your system.
  481.    * (I define mine in the compiler command line in my Makefile.LvR)
  482.    * (I leave mine alone and keep to the maximum. DjG)
  483.    */
  484.  
  485. #ifndef DFLTBITS
  486. #define DFLTBITS MAXBITS
  487. #endif
  488. #if (DFLTBITS < MINBITS)
  489. #undef DFLTBITS
  490. #define DFLTBITS MINBITS
  491. #endif
  492. #if (DFLTBITS > MAXBITS)
  493. #undef DFLTBITS
  494. #define DFLTBITS MAXBITS
  495. #endif
  496.  
  497. /* THIS IS TO COMPILE A 13 BIT MODEL IN SMALL MEMORY AND NEAR HEAP */
  498. /* AS SET UP IT WILL WORK WITH MICROSOFT C COMPILER                */
  499.  
  500. #if (MAXBITS < 14)
  501. #ifdef SMALLMODEL
  502. #define NEARHEAP TRUE
  503. #undef FAR
  504. #define FAR
  505. #endif
  506. #endif
  507.  
  508. /* correcting for different types of pointer arithmatic */
  509. /* probably won't have to change it                     */
  510. #define NULLPTR(type)   ((type FAR *) NULL)
  511.  
  512.  
  513. /* in making this program portable the following allocation and          */
  514. /* free functions are called, with the following parameters:             */
  515. /*        ALLOCTYPE FAR *emalloc(unsigned int x, int y)                  */
  516. /*                 void  efree(ALLOCTYPE FAR *ptr)                       */
  517. /* you must define the allocation function and the free function         */
  518. /* keep in mind that the casts must be correct for your compiler         */
  519. /* NOTE these are the two functions to change for allocating pointers to */
  520. /* far data space if you are not using Microsoft C v.5.1                 */
  521. /* Consult your compiler manual and find the low level function that     */
  522. /* returns a far pointer when compiled in the small model.               */
  523. /* if your compiler does not support that, you will have to compile with */
  524. /* a model that defaults to far pointers to data (compact or large model)*/
  525. /* HERE ARE SOME SAMPLE PREDEFINED ONES                                  */
  526.  
  527. #ifdef MSC
  528. #include <malloc.h>
  529. #ifdef NEARHEAP
  530. #define ALLOCATE(x,y)   malloc((size_t)((x)*(y)))
  531. #define FREEIT(ptr)     free((ptr))
  532. #else
  533. #define ALLOCATE(x,y)   _fmalloc((size_t)((x)*(y)))
  534. #define FREEIT(ptr)     _ffree((ptr))
  535. #endif
  536. #endif
  537.  
  538. #ifdef HUGE
  539. #include <malloc.h>
  540. #define ALLOCATE(x,y)   halloc((long)(x),(size_t)(y))
  541. #define FREEIT(ptr)     hfree(ptr)
  542. #endif
  543.  
  544. #ifdef __TURBOC__
  545. #include <alloc.h>
  546. #ifdef NEARHEAP
  547. #define ALLOCATE(x,y)  malloc((unsigned int)((x)*(y)))
  548. #define FREEIT(x)      free(x)
  549. #else
  550. #define ALLOCATE(x,y)  farmalloc((unsigned long)((x)*(y)))
  551. #define FREEIT(x)    farfree(x)
  552. #endif
  553. #endif
  554.  
  555. /* default allocation function, in segmented addressing, must return */
  556. /* a far pointer or compile with far pointer data as default         */
  557. #ifndef ALLOCATE
  558. #include <malloc.h>
  559. #define ALLOCATE(x,y)   malloc((unsigned int)x*y)
  560. #define FREEIT(ptr)     free((ptr))
  561. #endif
  562.  
  563.  
  564. # ifdef MAXSEG_64K
  565. #   if  MAXBITS > 14
  566. #       define SPLIT_HT   TRUE
  567. #   else
  568. #       define SPLIT_HT   0
  569. #   endif
  570. # else
  571. #   define SPLIT_HT   0
  572. # endif
  573.  
  574. # ifdef MAXSEG_64K
  575. #   if  MAXBITS > 15
  576. #       define SPLIT_PFX   TRUE
  577. #   else
  578. #       define SPLIT_PFX   0
  579. #   endif
  580. # else
  581. #   define SPLIT_PFX   0
  582. # endif
  583.  
  584. #ifndef BUFSIZ
  585. #define BUFSIZ 512
  586. #endif
  587.  
  588. #ifdef NO_SETBUF
  589. #define NO_SETVBUF
  590. #endif
  591.  
  592. #ifdef NO_SETVBUF
  593. #   ifndef NO_SETBUF
  594. #       define setvbuf(fp,buf,mode,size) setbuf((fp),(buf))
  595. #       define ZBUFSIZE BUFSIZ
  596. #       define XBUFSIZE BUFSIZ
  597. #   else
  598. #       define setvbuf(fp,buf,mode,size)
  599. #       define ZBUFSIZE (1)
  600. #       define XBUFSIZE (1)
  601. #   endif
  602. #else
  603. #   ifdef NEARHEAP
  604. #       define XBUFSIZE    (0xC00)
  605. #       define ZBUFSIZE    (0x1800)
  606. #   else
  607. #       define XBUFSIZE    (0x3000)      /* 12k bytes */
  608. #       define ZBUFSIZE    (0x6000)      /* 24k bytes */
  609. #   endif
  610. #endif
  611.  
  612. #define UNUSED      ((CODE)0)   /* Indicates hash table value unused    */
  613. #define CLEAR       ((CODE)256) /* Code requesting table to be cleared  */
  614. #define FIRSTFREE   ((CODE)257) /* First free code for token encoding */
  615. #define MAXTOKLEN   512         /* Max chars in token; size of buffer   */
  616. #define OK          0           /* Result codes from functions:         */
  617.  
  618. #ifdef vms
  619. #define ERROR       0x10000004  /* General unspecified error            */
  620. #define NORMAL      1           /* No error                             */
  621. #define unlink(x)   remove(x)
  622. #else
  623. #    define NORMAL      0
  624. #    ifdef ERROR
  625. #        if (ERROR == NORMAL)
  626. #            define ERROR   1   /* force redefine if (ERROR == NORMAL)  */
  627. #        endif
  628. #    else
  629. #        define ERROR       1
  630. #    endif
  631. #endif
  632.  
  633. #define SIGNAL_ERROR -1         /*   signal function error              */
  634. #define NOMEM       2           /*   Ran out of memory                  */
  635. #define TOKTOOBIG   3           /*   Token longer than MAXTOKLEN chars  */
  636. #define READERR     4           /*   I/O error on input                 */
  637. #define WRITEERR    5           /*   I/O error on output                */
  638. #define INFILEBAD   6           /*   Infile not in compressed format    */
  639. #define CODEBAD     7           /*   Infile contained a bad token code  */
  640. #define TABLEBAD    8           /*   The tables got corrupted (!)       */
  641. #define NOSAVING    9           /*   no saving in file size             */
  642. #define NOTOPENED  10           /*   output file couldn't be opened     */
  643. #define YES         1
  644. #define NO          0
  645.  
  646.  
  647. #include "compress.fns"
  648.  
  649. /* defines opening mode for files */
  650. /* and suffixes for compressed file */
  651.  
  652. #ifdef MSDOS
  653. #define WRITE_FILE_TYPE "wb"
  654. #define READ_FILE_TYPE "rb"
  655. #define SUFFIX "Z"
  656. #else
  657. #ifdef vms
  658. #define SUFFIX "_Z"
  659. #define WRITE_FILE_TYPE "wb"
  660. #define READ_FILE_TYPE "rb"
  661. #else
  662. #define WRITE_FILE_TYPE "w"
  663. #define READ_FILE_TYPE "r"
  664. #define SUFFIX ".Z"
  665. #endif
  666. #endif
  667.  
  668. /* The VERBOSE flag defines the default value of the verbose variable */
  669. /* If it's not already defined, we set it to FALSE here since most */
  670. /* systems set the default that way.  -Dal */
  671. #ifndef VERBOSE
  672. #define VERBOSE FALSE
  673. #endif
  674.  
  675. /* Defines for third byte of header */
  676. #define BIT_MASK    0x1f
  677. #define BLOCK_MASK  0x80
  678. /* Masks 0x40 and 0x20 are free.  I think 0x20 should mean that there is
  679.    a fourth header byte (for expansion).
  680. */
  681.  
  682.  
  683. #define CHECK_GAP 10000L     /* ratio check interval */
  684.  
  685. #ifdef MAIN
  686. UCHAR magic_header[] = { 0x1F,0x9D };  /* 1F 9D */
  687.  
  688. char rcs_ident[] = TITLE;
  689.  
  690. #ifdef MWC
  691. long _stksize = 20000L;     /* set MWC's stack to 20,000 */
  692. #ifdef MWC_NAME           /* if defined in makefile set _cmdname for */
  693. char _cmdname[]=MWC_NAME;   /* compress,zcat,uncomp check for desktop and */
  694. #endif                      /* dumb shells */
  695. #endif
  696.  
  697. #ifdef SOZOBON
  698. long _STKSIZ = 20000L;      /* set runtime stack to 20,000 bytes */
  699. #ifndef CMDNAME
  700. #define CMDNAME "compress"
  701. #endif
  702. #endif
  703.  
  704. int overwrite = 0;          /* Do not overwrite unless given -f flag */
  705. int maxbits = DFLTBITS;     /* user settable max # bits/code */
  706.  
  707. int exit_stat = 0;
  708. int keep = KEEPFLAG;            /* True = don't kill file */
  709. int keep_error = FALSE;     /* True = keep output file even if error exist */
  710. char *prog_name;
  711. char ifname[_MAX_DIR];
  712. char inpath[_MAX_DIR];
  713. char ofname [_MAX_DIR];
  714. char outpath[_MAX_DIR];
  715. int is_list = FALSE;            /* flag for file parameters */
  716. char endchar[1];
  717. char xbuf[XBUFSIZE];
  718. char zbuf[ZBUFSIZE];
  719. #ifdef MSDOS
  720. char separator[] = "\\";
  721. #else
  722. char separator[] = "/";
  723. #endif
  724. int nomagic = FALSE;  /* Use a 3-byte magic number header, unless old file */
  725. int zcat_flg = FALSE; /* Write output on stdout, suppress messages */
  726. int quiet = !VERBOSE; /* don't tell me about compression */
  727. /*
  728.  * block compression parameters -- after all codes are used up,
  729.  * and compression rate changes, start over.
  730.  */
  731. int block_compress = BLOCK_MASK;
  732. #ifdef COMP40
  733. long int ratio = 0L;
  734. long checkpoint = CHECK_GAP;
  735. #endif
  736.  
  737. /* force the overwrite */
  738. int force = 0;
  739.  
  740. #ifdef DEBUG
  741. int verbose = VERBOSE;
  742. int debug = FALSE;
  743. #endif /* DEBUG */
  744.  
  745. #ifndef NOSIGNAL
  746. SIGTYPE (*bgnd_flag)();
  747. #endif
  748.  
  749. int do_decomp = FALSE;
  750.  
  751. #else               /* not defining instance */
  752.  
  753. extern UCHAR magic_header[];
  754. extern char rcs_ident[];
  755. #ifdef MWC
  756. extern long _stksize;
  757. #endif
  758. extern int overwrite;
  759. extern int maxbits;
  760.  
  761.  
  762. extern int exit_stat;
  763. extern int keep;
  764. extern int keep_error;
  765. extern char *prog_name;
  766. extern char inpath[];
  767. extern char outpath[];
  768. extern int is_list;
  769. extern char endchar[];
  770. extern char xbuf[];
  771. extern char zbuf[];
  772. extern char ifname[];
  773. extern char ofname[];
  774. extern char separator[];
  775. extern int nomagic;
  776. extern int zcat_flg;
  777. extern int quiet;
  778. extern int block_compress;
  779. #ifdef COMP40
  780. extern long int ratio;
  781. extern long checkpoint;
  782. #endif
  783. extern int force;
  784.  
  785. #ifdef DEBUG
  786. extern int verbose;
  787. extern int debug;
  788. #endif /* DEBUG */
  789.  
  790. #ifndef NOSIGNAL
  791. extern SIGTYPE (*bgnd_flag)();
  792. #endif
  793. extern int do_decomp;
  794. #endif
  795.